package com.europe.business.europebusiness.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.europe.business.europebusiness.R;
import com.europe.business.europebusiness.ui.activity.WebViewActivity;
import com.europe.business.europebusiness.ui.bean.News;

import java.util.List;

public class RecomandNewsAdapter extends RecyclerView.Adapter<RecomandNewsAdapter.RecomandCompanyViewHolder>{

    private Context mContext;
    private List<News> mData;

    public RecomandNewsAdapter(Context mContext, List<News> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @NonNull
    @Override
    public RecomandCompanyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View itemView= LayoutInflater.from(mContext).inflate(R.layout.item_recomand_news,viewGroup,false);
        RecomandCompanyViewHolder recomandCompanyViewHolder=new RecomandCompanyViewHolder(itemView);
        return recomandCompanyViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecomandCompanyViewHolder recomandCompanyViewHolder, final int i) {
        recomandCompanyViewHolder.newsName.setText(mData.get(i).getNewsName());
        recomandCompanyViewHolder.newsType.setText(mData.get(i).getType());
        recomandCompanyViewHolder.newsDate.setText(mData.get(i).getDate());
        recomandCompanyViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, WebViewActivity.class);
                intent.putExtra("title",mData.get(i).getNewsName());
                intent.putExtra("time",mData.get(i).getDate());
                intent.putExtra("type",mData.get(i).getType());
                intent.putExtra("content", mData.get(i).getNewsContent());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class RecomandCompanyViewHolder extends RecyclerView.ViewHolder{

        public ImageView newsLogo;
        public TextView newsName;
        public TextView newsType;
        public TextView newsDate;
        public RecomandCompanyViewHolder(@NonNull View itemView) {
            super(itemView);
            newsLogo = itemView.findViewById(R.id.news_logo);
            newsName = itemView.findViewById(R.id.news_name);
            newsType = itemView.findViewById(R.id.news_type);
            newsDate = itemView.findViewById(R.id.news_date);
        }

    }
}
